<template>
  <div class="archive-container">
    <div class="archive">
      <div class="archive-left">
        <h1>文章时间轴</h1>
        <div class="timeline">
          <div v-for="item in archiveList" :key="item.groupYear">
            <h2 class="timeline__item timeline__item--year">
              {{ item.groupYear }}
            </h2>
            <div
              class="timeline__item"
              v-for="item in item.articles"
              :key="item.articleId"
              style="display: flex"
            >
              <router-link
                :to="{
                  path: '/articleDetail',
                  query: { articleId: item.articleId },
                }"
                style="color: #717171"
              >
                <h4 class="timeline__title">
                  {{ item.articleTitle }}
                </h4></router-link
              >
              <span class="timeline__time" style="color: #717171">{{
                item.updateTime | formatDate
              }}</span>
            </div>
          </div>
        </div>
      </div>
      <div class="achive-right">
        <div class="achive-reccomd">
          <div class="achive-rtop">
            <i class="iconfont" class="color: red;">&#xe8ab;</i>热门推荐
          </div>
          <div class="achive-rboot">
            <ul>
              <li v-for="(item, index) in archiveHotList" :key="item.articleId">
                <router-link
                  :to="{
                    path: '/articleDetail',
                    query: { articleId: item.articleId },
                  }"
                >
                  <div class="achive-number">
                    <p>{{ index + 1 }}</p>
                  </div>
                  <div class="rboot-achive">
                    <p>{{ item.articleTitle }}</p>
                    <!-- 这里的意思是 如果你formatDate存在 并且前有值就会默认调用后面那个过滤器 -->
                    <span style="margin: left">{{
                      item.updateTime | formatDate
                    }}</span>
                    <span style="float: right">{{ item.typeName }}</span>
                  </div>
                </router-link>
              </li>
            </ul>
          </div>
        </div>
        <div class="archive-right-second">
          <div class="archive-hot-questions">
            <div class="archive-hot-quest"></div>
            <p>热点问题</p>
          </div>
          <hr style="width: 100%; height: 1px; margin-top: 2%" />
          <div class="archive-hot-passage">
            <ul>
              <li v-for="item in archiveHotquestionList" :key="item.questionId">
                <router-link to="">
                  <i class="iconfont">&#xe626;</i>
                  <p>{{ item.questionTitle }}</p>
                </router-link>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import "@/assets/css/archive.css";
import {
  getArchiveList,
  getArchiveHotList,
  getArchiveHotquestionList,
} from "@/api/archive";
import { formatDate } from "@/utils/date";
export default {
  name: "archive",
  data() {
    return {
      archiveList: [],
      archiveHotList: [],
      archiveHotquestionList: [],
    };
  },
  created() {
    this.getArchiveListFun();
    this.getArchiveHotquestionListFun();
    this.getArchiveHotListFun();
  },
  // 创建一个过滤器
  filters: {
    formatDate(time) {
      if (time == null || time === "") {
        return "N/A";
      }
      let date = new Date(time);
      return formatDate(date, "yyyy-MM-dd");
    },
  },
  methods: {
    getArchiveListFun() {
      getArchiveList().then((response) => {
        console.log(response.data);
        this.archiveList = response.data;
      });
    },
    getArchiveHotListFun() {
      getArchiveHotList().then((response) => {
        this.archiveHotList = response.data;
      });
    },
    getArchiveHotquestionListFun() {
      getArchiveHotquestionList().then((response) => {
        this.archiveHotquestionList = response.data;
      });
    },
  },
};
</script>
<style>
* {
  box-sizing: border-box;
}
a {
  text-decoration: none;
  color: black;
}
h1 {
  text-align: center;
  font-family: "Raleway", sans-serif;
}
.timeline {
  position: relative;
  padding: 1rem;
  margin: 0 auto;
  /* max-width: 1300px; */
}
.timeline:before {
  content: "";
  position: absolute;
  height: 100%;
  border: 1px solid hotpink;
  right: 40px;
  top: 0;
}

.timeline__time {
  line-height: 23px;
  margin-left: 30px;
}
.timeline:after {
  content: "";
  display: table;
  clear: both;
}
@media screen and (min-width: 700px) {
  .timeline {
    padding: 2rem;
  }
  .timeline:before {
    left: calc(50% - 1px);
    right: auto;
  }
}
.timeline__item {
  padding: 1rem;
  border: 2px solid hotpink;
  border-image: linear-gradient(to right, skyblue 0%, hotpink 100%);
  border-image-slice: 1;
  position: relative;
  margin: 1rem 3rem 1rem 1rem;
  clear: both;
}
.timeline__item:after,
.timeline__item:before {
  content: "";
  position: absolute;
}
.timeline__item:before {
  right: -10px;
  top: calc(50% - 5px);
  border-style: solid;
  border-color: hotpink hotpink transparent transparent;
  border-width: 10px;
  transform: rotate(45deg);
}
@media screen and (min-width: 700px) {
  .timeline__item {
    width: 44%;
    margin: 1rem;
  }
  .timeline__item:nth-of-type(2n) {
    float: right;
    margin: 1rem;
    border-image: linear-gradient(to right, hotpink 0%, skyblue 100%);
    border-image-slice: 1;
  }
  .timeline__item:nth-of-type(2n):before {
    right: auto;
    left: -10px;
    border-color: transparent transparent hotpink hotpink;
  }
}
.timeline__item--year {
  text-align: center;
  max-width: 150px;
  margin: 0 48px 0 auto;
  border-radius: 25px;
  font-size: 1.8rem;
  background-color: #fff;
  line-height: 25px;
  border-image: none;
  padding: 0.5rem 1rem 1rem;
}
.timeline__item--year:before {
  display: none;
}
@media screen and (min-width: 700px) {
  .timeline__item--year {
    text-align: center;
    margin: 0 auto;
  }
  .timeline__item--year:nth-of-type(2n) {
    float: none;
    margin: 0 auto;
    border-image: none;
  }
  .timeline__item--year:nth-of-type(2n):before {
    display: none;
  }
}
.timeline__title {
  margin: 0;
  font-family: "Raleway", sans-serif;
  font-size: 1em;
}
.timeline__title:hover{
  color:pink;
}
.timeline__blurb {
  line-height: 1.5;
  font-size: 1rem;
  margin: 0.5rem 0 0;
}
</style>
